<!--
 * @Author: ZCL
 * @Date: 2020-05-18 14:17:47
 * @LastEditors: ZCL
 * @LastEditTime: 2020-05-18 14:17:47
-->
<template>
  <!-- 资产名称 -->
  <div class="myCollectingDetail">
    <Carousel :assetInfoList="assetInfoList" />
    <Form :form-type="$operate" @submit="handleSubmit" ref="form"/>
  </div>
</template>

<script>
import Carousel from '@/components/Carousel';
import Form from '@/components/Form';
import titleMixins from '@/mixins/title';
import { EDIT_TYPES, FORM_TYPES } from '@/constant';

export default {
  name: 'MyCollectingDetail',
  mixins: [titleMixins],
  components: {
    Carousel,
    Form
  },
  props: ['$operate', 'id'],
  data () {
    return {
      EDIT_TYPES,
      assetInfoList: {}, // 资产信息
      formData: {}
    };
  },
  methods: {
    // 获取资产信息详情,回显轮播图组件
    getAssetInfo () {
      let params = {
        id: this.id
      };
      this.$api.getAssetInfo(params).then(res => {
        if (res.code === 0) {
          this.assetInfoList = res.result;
        }
      });
    },
    // 回显数据分发函数
    handleGetData () {
      const { $edit, $operate } = this;
      if ($edit === EDIT_TYPES.EDIT) {
        switch ($operate) {
          case FORM_TYPES.REPAIR: this.handleGetRepairEdit(); break; // 维修编辑回显
        }
      }
    },
    // 提交分发函数
    handleSubmit (params) {
      console.log('submit', params);
      const { $edit, $operate } = this;
      // 创建
      if ($edit === EDIT_TYPES.CREATE) {
        switch ($operate) {
          case FORM_TYPES.TRANSFER: this.handleCreateTransfer(params); break; // 转移
        }
      } else if ($edit === EDIT_TYPES.EDIT) {
        switch ($operate) {
        }
      }
    },
    // 回显数据
    handleSetUp (data) {
      this.$refs.form.handleSetUp(data);
    },
    // 创建领取
    handleCreateReceive () {},
    // 创建维修
    handleCreateRepair () {},
    // 创建转移
    handleCreateTransfer (params) {
      this.$api.postTransferAddTransfer(params).then(res => {
        if (res.code === 0) {
          console.log('创建成功');
        }
      });
    },
    // 创建退回
    handleCreateReturn () {},
    // 创建丢失
    handleCreateLoss () {},
    // 创建盘点
    handleCreateInventory () {
    },
    // 获取领取编辑
    handleGetReceiveEdit () {},
    // 获取维修编辑
    handleGetRepairEdit () {
      const params = {
        id: this.id
      };
      this.$api.getRepaireditRepair(params).then(res => {
        if (res.code === 0) {
          this.handleSetUp(res.result);
        }
      });
    },
    // 获取转移编辑
    handleGetTransferEdit () {},
    // 获取回退编辑
    handleGetReturnEdit () {},
    // 获取报失编辑
    handleGetLossEdit () {},
    // 获取盘点编辑
    handleGetInventoryEdit () {
    },
    // 保存领取编辑
    handleSaveReceiveEdit () {},
    // 保存维修编辑
    handleSaveRepairEdit () {},
    // 保存转移编辑
    handleSaveTransferEdit () {
    },
    // 保存转移编辑
    handleSaveReturnEdit () {},
    // 保存丢失编辑
    handleSaveLossEdit () {},
    // 保存盘点编辑
    handleSaveInventoryEdit () {
    },
    // 获取领取详情
    handleGetReceiveDetail () {},
    // 获取报修详情
    handleGetRepairDetail () {
      const params = {
        id: this.id
      };
      this.$api.getRepairRepairInfo(params).then(res => {
        if (res.code === 0) {
          this.handleSetUp(res.result);
        }
      });
    },
    // 获取转移详情
    handleGetTransferDetail () {},
    // 获取回退详情
    handleGetReturnDetail () {},
    // 获取报失详情
    handleGetLossDetail () {},
    // 获取盘点结果
    handleGetInventoryDetail () {
    }
  },
  created () {
    this.getAssetInfo();// 获取资产信息详情
    // 只有编辑和获取详情初始化
    if ([EDIT_TYPES.EDIT, EDIT_TYPES.DETAIL].includes(this.$edit)) {
      this.handleGetData();
    }
  }
};
</script>

<style lang="scss" scoped>
.myCollectingDetail {

}
</style>
